//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    typeId: 0,
    isAsc: true,
    teacherId: "",
    // 
    imgUrl: baseJs.imgUrl,
    pageIndex:1,
    state:"",
    courseList:[],

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
      teacherId: options.id
    })
    this.GetTeacherCourse();
  },

  //
  GetTeacherCourse: function() {
    var that = this;
    var pageIndex = this.data.pageIndex;
    var typeId = this.data.typeId;
    var teacherId = this.data.teacherId;
    var isAsc = this.data.isAsc;
    var courseList = this.data.courseList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=GetTeacherCourse&PageSize=10&PageIndex=" + pageIndex + "&CourseType=" + typeId + "&IsAsc=" + isAsc + "&teacherId=" + teacherId),
      success: function(res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          courseList.push(json[i])
        }
        that.setData({
          courseList: courseList,
        })
        console.log(courseList);
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }

      }
    })
  },
})